package com.neasho.neashoadminv1.infrastructure.domain.sys

import com.neasho.neashoadminv1.infrastructure.domain.base.BasePermissionEntity
import org.babyfish.jimmer.sql.DissociateAction
import org.babyfish.jimmer.sql.Entity
import org.babyfish.jimmer.sql.IdView
import org.babyfish.jimmer.sql.JoinColumn
import org.babyfish.jimmer.sql.Key
import org.babyfish.jimmer.sql.ManyToOne
import org.babyfish.jimmer.sql.OnDissociate
import org.babyfish.jimmer.sql.OneToMany
import org.babyfish.jimmer.sql.Table

/**
 * 系统 - 部门表
 */
@Entity
@Table(name = "sys_dept")
interface SysDept : BasePermissionEntity {

    /**
     * 部门名
     */
    @Key
    val name: String

    /**
     * 部门id
     */
    @IdView
    val parentId: Long?

    /**
     * 父部门
     */
    @ManyToOne
    @JoinColumn(name = "parent_id")
    @OnDissociate(DissociateAction.SET_NULL)
    val parent: SysDept?

    @OneToMany(mappedBy = "dept")
    val users: List<SysUser>

}

